package com.net.xpay.admin.controller.admin;

import com.net.common.model.ResultData;
import com.net.common.model.ResultPagedList;
import com.net.xpay.common.domain.UserBusinessAuth;
import com.net.xpay.common.manager.UserBusinessAuthManager;
import com.net.xpay.common.service.UserBusinessAuthService;
import com.net.xpay.core.model.AdminUserBusinesAuthSearchModel;
import com.net.xpay.core.model.AdminUserBusinessAuthModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/user-business-auth")
@Api(tags = "运营/ 账户企业认证", description = "运营 账户企业认证 net")
public class AdminUserBusinessAuthController {

    @Autowired
    private UserBusinessAuthManager userBusinessAuthManager;

    @Autowired
    private UserBusinessAuthService userBusinessAuthService;

    @ApiOperation("搜索账本账户审核")
    @PostMapping("/search")
    @ResponseBody
    @PreAuthorize("hasAnyRole('ADMIN', 'user-business-auth::search')")
    public ResultPagedList<UserBusinessAuth> searchUserBusinessAuth(@RequestBody AdminUserBusinesAuthSearchModel searchModel) {
        List<UserBusinessAuth> records = userBusinessAuthManager.search(searchModel);
        long count = userBusinessAuthManager.searchCount(searchModel);
        return new ResultPagedList<>(records, count, searchModel);
    }

    @ApiOperation("审核通过")
    @PostMapping("/audit-success")
    @ResponseBody
    @PreAuthorize("hasAnyRole('ADMIN', 'user-business-auth::audit-success')")
    public ResultData<Boolean> auditSuccess( Long id) {

        userBusinessAuthService.auditSuccess(id);
        return new ResultData<>(true);
    }

    @ApiOperation("审核失败")
    @PostMapping("/audit-fail")
    @ResponseBody
    @PreAuthorize("hasAnyRole('ADMIN', 'user-business-auth::audit-fail')")
    public ResultData<Boolean> auditFail( @RequestBody AdminUserBusinessAuthModel model) {

        userBusinessAuthService.auditFail(model);
        return new ResultData<>(true);
    }
}
